package com.jaya.budan.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.jaya.budan.R;
import com.jaya.budan.bean.ListUser_Information;
import com.jaya.budan.bean.User_Limit;

import java.util.List;

public class Photo_Album_Adapter extends BaseAdapter {

    private Context mcontext;
    private List<String> mlist;
    private List<User_Limit> user_limit;
    private List<ListUser_Information.Files> files;
    private int mtype;

    public Photo_Album_Adapter(Context context, List<String> list, List<ListUser_Information.Files> file, List<User_Limit> limits, int type) {
        mlist = list;
        files = file;
        mtype = type;
        mcontext = context;
        user_limit = limits;
    }

    @Override
    public int getCount() {
        if (mtype == 1){
            return files.size();
        } else if (mtype == 3){
            return user_limit.size();
        } else {
            return mlist.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mtype == 1){
            return files.get(position);
        } else if (mtype == 3){
            return user_limit.get(position);
        } else {
            return mlist.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint({"ViewHolder", "SetTextI18n"})
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (mtype == 3){
            convertView = convertView.inflate(mcontext, R.layout.geren_main_pl_lv_item, null);
            TextView tv_pl_item_name = convertView.findViewById(R.id.tv_pl_item_name);
            TextView tv_pl_item_comment = convertView.findViewById(R.id.tv_pl_item_comment);
            tv_pl_item_name.setText("" + user_limit.get(position).getNicename() + "：" + user_limit.get(position).getTo_nicename());
            tv_pl_item_comment.setText("" + user_limit.get(position).getComment());
        } else if (mtype == 2){
            convertView = convertView.inflate(mcontext, R.layout.lv_geren_update_msg_home_item, null);
            TextView tv_xyfjilu_name = convertView.findViewById(R.id.tv_xyfjilu_name);
            tv_xyfjilu_name.setText("" + mlist.get(position));
        } else if (mtype == 1){
            convertView = convertView.inflate(mcontext, R.layout.gv_photoalbum_item, null);
            ImageView iv_photo_album_icon = convertView.findViewById(R.id.iv_photo_album_icon);
            Glide.with(mcontext).load(files.get(position).getPath() + "").apply(new RequestOptions()
                    .placeholder(R.mipmap.fill_person_icon).error(R.mipmap.fill_person_icon)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_photo_album_icon);
        } else {
            convertView = convertView.inflate(mcontext, R.layout.gv_photoalbum_item, null);
            ImageView iv_photo_album_icon = convertView.findViewById(R.id.iv_photo_album_icon);
            Glide.with(mcontext).load(mlist.get(position) + "").apply(new RequestOptions()
                    .placeholder(R.mipmap.fill_person_icon).error(R.mipmap.fill_person_icon)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_photo_album_icon);
        }
        return convertView;
    }
}
